#
# Copyright (c) 2022-present, IO Visor Project
# All rights reserved.
#
# This source code is licensed in accordance with the terms specified in
# the LICENSE file found in the root directory of this source tree.
#

if(NOT CPACK_GENERATOR)
  message(FATAL_ERROR "ubpf - No generator selected")
endif()

set(CPACK_PACKAGE_VERSION "${UBPF_VERSION}")
set(CPACK_PACKAGE_DESCRIPTION "Userspace eBPF VM")
set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "IO Visor Project")
set(CPACK_PACKAGE_CONTACT "contact-us@iovisor.org")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.iovisor.org")
set(CPACK_PACKAGE_RELOCATABLE ON)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")

if(CPACK_GENERATOR STREQUAL "DEB")
  set(CPACK_STRIP_FILES ON)
  set(CPACK_DEBIAN_UBPF_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
  set(CPACK_DEBIAN_PACKAGE_RELEASE "${CPACK_PACKAGE_VERSION}")
  set(CPACK_DEBIAN_UBPF_FILE_NAME "DEB-DEFAULT")
  set(CPACK_DEBIAN_PACKAGE_PRIORITY "extra")
  set(CPACK_DEBIAN_PACKAGE_SECTION "default")
  set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>=2.31), zlib1g")
  set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}")

  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CPACK_DEB_COMPONENT_INSTALL ON)
    set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON)
  endif()

elseif(CPACK_GENERATOR STREQUAL "RPM")
  set(CPACK_STRIP_FILES ON)
  set(CPACK_RPM_PACKAGE_RELEASE "${CPACK_PACKAGE_VERSION}")
  set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
  set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")
  set(CPACK_RPM_PACKAGE_GROUP "default")
  set(CPACK_RPM_PACKAGE_LICENSE "Apache 2.0")
  set(CPACK_RPM_PACKAGE_REQUIRES "glibc >= 2.31, zlib")

  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CPACK_RPM_DEBUGINFO_PACKAGE ON)
    set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/usr/src/debug/ubpf")
    set(CPACK_RPM_DEBUGINFO_FILE_NAME "RPM-DEFAULT")
  endif()

elseif(CPACK_GENERATOR STREQUAL "TGZ")
  set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)

  if(NOT PLATFORM_WINDOWS)
    set(CPACK_SET_DESTDIR ON)
  endif()
endif()

include("CPack")
